package com.hcy.schedulingapi.task;

import com.hcy.rabbitbasicutils.utils.RedisUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/1/14 18:04
 */
@EnableScheduling
@Configuration
public class DelayTask{

    Logger logger = LoggerFactory.getLogger(DelayTask.class);

    /**
     * redis geo key
     */
    @Value("${CAR_GEO_KEY}")
    private String CAR_GEO_KEY;
    @Value("${CAR_GEO_KEY_EXPIRE}")
    private String CAR_GEO_KEY_EXPIRE;

    @Autowired
    RedisUtils redisUtils;

    /**
     * @Author huchenying
     * @Description 利用lua脚本清除下线的车
     * @Date  2022/1/14 18:10
     **/
    @Scheduled(fixedDelay = 60000)
    public void refreshCarLoc(){
        try {
            redisUtils.refreshCarLoc(CAR_GEO_KEY_EXPIRE,CAR_GEO_KEY);
            logger.info("清除下线的车 autoTask 执行成功！");
        } catch (Exception e) {
            logger.error("清除下线的车定时任务执行失败！",e);
        }
    }
}
